package HashMap;

import java.util.HashMap;

public class Test1 {
    public static void main(String[] args) {
        //创建集合
        HashMap<Student,String> map=new HashMap<>();
        //创建学生对象
        Student s1=new Student("zhangsan",18);
        Student s2=new Student("lisi",19);
        Student s3=new Student("wangwu",20);
        Student s4=new Student("wangwu",20);

        //添加元素
        map.put(s1,"guangdong");
        map.put(s2,"jiangxi");
        map.put(s3,"anhui");
        map.put(s4,"guangxi");

        //遍历
        //1.通过键找值
        //Lambda表达式
//        Set<Student> set = map.keySet();
//        set.forEach((s)-> {
//                String val=map.get(s);
//            System.out.println(s+"="+val);
//            }
//        );
        //增强for循环
//        Set<Student> keys = map.keySet();
//        for (Student key : keys) {
//            String val=map.get(key);
//            System.out.println(key+"="+val);
//        }

        //2.通过键值对
//        Set<Map.Entry<Student, String>> entries = map.entrySet();
//        for (Map.Entry<Student, String> entry : entries) {
//            Student key = entry.getKey();
//            String value = entry.getValue();
//            System.out.println(key+"="+value);
        //3.Lambda表达式
        map.forEach((student, s)-> System.out.println(student+"="+s));





    }
}
